#include "Transform3D.h"
#include "support.h"
#include <QDebug>

Transform3D::Transform3D(const cv::Mat &transformationMatrix) : Filter(1, 1), transformationMatrix(transformationMatrix)
{
	
}


Transform3D::~Transform3D(void)
{
}

void Transform3D::Process()
{
	int pointsCount = inputs[0]->rows;
	outputs[0] = cv::Mat(pointsCount, 3, CV_32FC1);

	for (int i = 0; i < pointsCount; ++i)
	{
		cv::Mat vector = cv::Mat(1, 4, CV_32FC1, cv::Scalar(1.0));
		inputs[0]->row(i).copyTo(vector(cv::Rect(0, 0, 3, 1)));
		cv::Mat result = (transformationMatrix * vector.t()).t();
		result = result / result.at<float>(0, 3);
		result(cv::Rect(0, 0, 3, 1)).copyTo(outputs[0](cv::Rect(0,i,3,1)));
	}
}
